local jianyi = fk.CreateSkill {

  name = "joy__jianyi",

  tags = { Skill.Compulsory, },

}



jianyi:addEffect(fk.TurnEnd, {
  name = "joy__jianyi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(jianyi.name) then
      local ids = {}
      local events =  player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.moveReason == fk.ReasonDiscard then
            for _, info in ipairs(move.moveInfo) do
              if (Fk:getCardById(info.cardId).sub_type == Card.SubtypeArmor or Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon)
              and player.room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end, Player.HistoryTurn)
      if #ids > 0 then
        event:setCostData(self, ids)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local get = room:askForCardChosen(player, player, {card_data = {{jianyi.name, event:getCostData(self)}}}, jianyi.name)
    room:moveCards({
      ids = {get},
      to = player.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonPrey,
      proposer = player.id,
      skillName = jianyi.name,
    })
  end,
})

return jianyi